package com.example.knowledge.fragement;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import com.alibaba.android.arouter.launcher.ARouter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.baselib.base.BaseMVPFragment;
import com.example.baselib.baseurl.GuidUrl;
import com.example.baselib.mvp.IPresenter;
import com.example.knowledge.adapter.KnowConsultChildAdapter;
import com.example.knowledge.adapter.KnowCourseChildAdapter;
import com.example.knowledge.bean.TestKnowChildBean;
import com.example.news.R;

import java.util.ArrayList;
import java.util.List;

/**
 * 课程  子类fragment
 */
@SuppressLint("ValidFragment")
public class KonwCourseChildFragment extends BaseMVPFragment implements SwipeRefreshLayout.OnRefreshListener {
    private String mTitle;
    private SwipeRefreshLayout swipeRefreshLayout;
    private RecyclerView recyclerView;

    private KnowCourseChildAdapter knowConsultChildAdapter;
    private List<TestKnowChildBean> testKnowChildBeanList = new ArrayList<>();


    public static KonwCourseChildFragment getInstance(String title) {
        KonwCourseChildFragment sf = new KonwCourseChildFragment();
        sf.mTitle = title;
        return sf;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected IPresenter createPresenter() {
        return null;
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.fr_simple_card;
    }

    @Override
    protected void initView(View rootView) {
        swipeRefreshLayout = rootView.findViewById(R.id.swiprefreshlayout);
        recyclerView = rootView.findViewById(R.id.recycleview);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext,
                LinearLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(linearLayoutManager);

        knowConsultChildAdapter = new KnowCourseChildAdapter(R.layout.item_course_child_recycleview, testKnowChildBeanList);
        knowConsultChildAdapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);
        recyclerView.setAdapter(knowConsultChildAdapter);
        swipeRefreshLayout.setOnRefreshListener(this);
        knowConsultChildAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                ARouter.getInstance().build(GuidUrl.CourseDetail_Activity).navigation();
            }
        });
    }

    @Override
    protected void initData() {
        testKnowChildBeanList.add(new TestKnowChildBean("12:30", "治疗高血压，高血脂的经典方正！", "张学友  辽宁中医药大学院长", "3讲/¥120.00", "15324"));
        testKnowChildBeanList.add(new TestKnowChildBean("12:30", "治疗高血压，高血脂的经典方正！", "张学友  辽宁中医药大学院长", "3讲/¥120.00", "15324"));
        testKnowChildBeanList.add(new TestKnowChildBean("12:30", "治疗高血压，高血脂的经典方正！", "经方云", "3讲/¥120.00", "15324"));
        testKnowChildBeanList.add(new TestKnowChildBean("12:30", "治疗高血压，高血脂的经典方正！", "张学友  辽宁中医药大学院长", "3讲/¥120.00", "15324"));
        testKnowChildBeanList.add(new TestKnowChildBean("12:30", "治疗高血压，高血脂的经典方正！", "经方云", "3讲/¥120.00", "15324"));
        testKnowChildBeanList.add(new TestKnowChildBean("12:30", "治疗高血压，高血脂的经典方正！", "张学友  辽宁中医药大学院长", "3讲/¥120.00", "15324"));
        testKnowChildBeanList.add(new TestKnowChildBean("12:30", "治疗高血压，高血脂的经典方正！", "张学友  辽宁中医药大学院长", "3讲/¥120.00", "15324"));
        testKnowChildBeanList.add(new TestKnowChildBean("12:30", "治疗高血压，高血脂的经典方正！", "经方云", "3讲/¥120.00", "15324"));
        testKnowChildBeanList.add(new TestKnowChildBean("12:30", "治疗高血压，高血脂的经典方正！", "张学友  辽宁中医药大学院长", "3讲/¥120.00", "15324"));

        knowConsultChildAdapter.setNewData(testKnowChildBeanList);
        knowConsultChildAdapter.notifyDataSetChanged();

    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void onRefresh() {

    }
}